<template>
<view class="shop">
  <view v-for="(item, index) in shopList" :key="index" class="shopimg" :data-index="index" @tap="toShop">
    <image :src="item.store_logo" class="img"></image>
    <text class="text">{{item.store_name}}</text>
  </view>
</view>
</template>

<script>
// hotmall/packageB/shopList/shopList.js
import api from "../../../api";
var app = getApp();

export default {
  data() {
    return {
      shopList: [],
      shopID: [],
      shopName: [],
      shopLogo: []
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.globalData.request({
      url: api.default.selected_Shops,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值

      },
      method: 'POST',
      data: {
        address: '青岛'
      },
      success: res => {
        console.log(res);
        let id = [],
            name = [],
            logo = [];

        for (let i = 0; i < res.data.length; i++) {
          id = id.concat(res.data[i].id);
          name = name.concat(res.data[i].store_name);
          logo = logo.concat(res.data[i].store_logo);
        }

        this.setData({
          shopList: res.data,
          shopID: id,
          shopName: name,
          shopLogo: logo
        });
        console.log(logo);
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    wx.showLoading({
      title: '加载中'
    });
    this.onLoad();
    wx.hideLoading();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    //店铺路由
    toShop(e) {
      console.log(e);
      var l = e.currentTarget.dataset.index;
      console.log(l);
      var id = this.shopID[l];
      var name = this.shopName[l];
      var logo = this.shopLogo[l];
      console.log(logo);
      wx.navigateTo({
        url: '../../packageA/goodShop/goodShop?id=' + id + '&name=' + name + '&logo=' + logo
      });
    }

  }
};
</script>
<style>
@import "./shopList.css";
</style>